//
//  ViewController.m
//  03-UIResponder
//
//  Created by 曹曹 on 16/7/18.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    TouchView *view = [[TouchView alloc] init];
    view.frame = CGRectMake(100, 100, 200, 200);
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
    // 1.响应者链
    // 触摸TouchView时
    // 检测顺序: 硬件 → APPDelegate → UIApplication → UIWindow → UIViewController → self.view → TouchView
    // 响应顺序: TouchView → self.view → UIViewController → UIWindow → UIApplication → APPDelegate → nil
    // 如果所有的响应者都无法响应该事件, 则该事件会被舍弃
    // 两种监测响应者的方法:
    // 1. Category 实现 touchesBegan方法
    // 2. nextResponder
    // 例子:
    // 1. 响应者不要出边界, 出边界的响应者无法响应
    // 判断当前的点, 在不在范围内(pointInside:withEvent) (这个方法返回的是BOOl值)
    BOOL isInside = [view pointInside:CGPointMake(10, 10) withEvent:nil];
    NSLog(@"%@", isInside ? @"YES" : @"NO");
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor blueColor];
    button.frame = CGRectMake(10, 10, 100, 50);
    [view addSubview:button];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    // 2.Button的点击方法如何实现
    // Button点击效果通过UIResponder对应的方法实现
    // 3.pointInside重写, 实现失去响应能力(return NO)
    // 开启用户交互
    // button.userInteractionEnabled = YES;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//    [super touchesBegan:touches withEvent:event];
    NSLog(@"%@-------%s", self.class,  __FUNCTION__);
}
- (void)buttonClicked:(UIButton *)button {
    NSLog(@"%@", button);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
